﻿//共享资源URL
var __ShareURL = parent.location.toString();
//选中的朋友号
var _SR_CFNList = new Array();
//当前页朋友号列表()
var _SR_FriendNoList = new Array();
//当前会员好友数量
var _SR_MCOUNT = 0;
//好友页索引
var _SR_PageIndex = 1;
//全选后取消单个标记(true全选后取消单个)
var _SR_CheckAOrF = false;
//我的昵称名
var _SR_MyNickN = "";
var _SR_MyMemberNo = "";
//分页对象
var _SR_FriendPage = null;
var gPageIndex = 1;
var _SR_PageSize = 35;
var _SR_C0047 = "";var _SR_C0056 = "";var _SR_C0064 = "";var _SR_SR000 = "";var _SR_SR001 = "";var _SR_SR002 = "";var _SR_SR003 = "";var _SR_SR005 = "";
var _SR_SR006 = "";var _SR_SR009 = "";var _SR_SR010 = "";var _SR_SR011 = "";var _SR_SR012 = "";var _SR_SR014 = "";var _SR_SR017 = "";var _SR_SR018 = "";

function $ShareRes$()
{
    showProgressBar(false,true);
    WebServices.User.Public.GetShareResInfo(1,_SR_PageSize,$onsuccShareData$);
}
function $onsuccShareData$(result)
{
    showProgressBar(false,true);    
    if(result[0]=="NL")
    {
        $Login$($ShareRes$);return;
    }
    else if(result[0]=="F")
    {alert("F");_sr_Empty();return;
        //显示操作失败消息
    }
    else
    {//0：当前会员好友数量、1：朋友信息（号、昵称）、2：当前会员昵称名、3:文字相关、4：
        _SR_MCOUNT = result[0];_SR_MyNickN = result[2];        
        var friLength = result[1].length;
        _SR_C0047 = result[3][0];
        _SR_C0056 = result[3][1];
        _SR_C0064 = result[3][2];
        _SR_SR000 = result[3][3];
        _SR_SR001 = result[3][4];
        _SR_SR002 = result[3][5];
        _SR_SR003 = result[3][6];
        _SR_SR005 = result[3][7];
        _SR_SR006 = result[3][8];
        _SR_SR009 = result[3][9];
        _SR_SR010 = result[3][10];
        _SR_SR011 = result[3][11];
        _SR_SR012 = result[3][12];
        _SR_SR014 = result[3][13];
        _SR_SR017 = result[3][14];
        _SR_SR018 = result[3][15];
        var _title = result[3][16];_SR_FriendPage = result[4];_SR_MyMemberNo = result[5];
        $("$divIput$").style.display = "none";
        var srBody = "<div><div id='_sr_SendContent' style='display:none'><div class='popup_content' style='text-align:center'><strong>"+_SR_SR017+"</strong><div id='_sr_SendText'></div><input style='display:none' type='button' value='"+_SR_SR018+"' class='button' onclick='$sr_SendContents()' />&nbsp;&nbsp;<input type='button' value='"+_SR_C0064+"' class='buttong' onclick='_sr_Empty()' /></div></div><div id='_sr_Send'><div class='popup_content'><div><strong>"+_SR_SR005+":</strong><br /><input type='text' value='"+__ShareURL+"' class='common460' disabled='disabled' readonly='readOnly' /><div class='clear'></div></div><div class='margin20T'><ul class='sort_sel' style='width:540px'><li id='_sr_spanQuesType1' class='first selATags' onclick='$sr_ShowType(0)' style=' float:left'><span>"+_SR_SR000+"</span></li><li id='_sr_spanQuesType2' class='' onclick='$sr_ShowType(1)' style='float:left'><span>"+_SR_SR001+"</span></li></ul><div class='clear'></div></div><div id='_sr_askQuestype1'><div style='margin-top:10px'><div id='_sr_emOthErr' class='MessagePanel4' style='display:none'>"+_SR_SR003+"</div>"+_SR_SR002+"<p><textarea id='_sr_txtEmail' class='common460' rows='5'></textarea></p><input type='button' value='"+_SR_C0047+"' class='button' onclick='$SR_SendEmail()' />&nbsp;&nbsp;<input type='button' value='"+_SR_C0064+"' class='buttong' onclick='_sr_Empty()' /></div></div><div id='_sr_askQuestype2' style='display:none'><div id='_sr_SelectFriends' ><div style='border-bottom:1px #cccccc solid; padding-bottom:3px; margin-top:10px; margin-bottom:10px'><div style='float:left'>"+_SR_SR006+"</div><div style='float:right'><input type='checkbox' id='_sr_checkDel' title='"+_SR_SR009+" / "+_SR_C0056+"' onclick='$SR_CheckAllBox(this)' /><font color='#ff0000' size='1'>"+_SR_SR009+"</font></div><div class='clear'></div></div><div id='_sr_error1ID' style='display:none'><div class='MessagePanel4'><div style='margin-left:10px'>"+_SR_SR014+"</div></div></div><div id='_sr_FriendsList'><ul class='tag_common_right'>";
        for(var i=0; i < friLength; i++)
        {
            _SR_FriendNoList[i] = result[1][i].MemberNo;
            srBody+="<li><input type='checkbox' id='"+result[1][i].MemberNo+"' value='"+result[1][i].Nickname+"' onclick='$sr_CheckFriend(\""+result[1][i].MemberNo+"\",this)' /> <a href='/"+result[1][i].MemberNo+".htm' target='_blank'>"+result[1][i].Nickname+"</a></li>";
        }
        srBody+="</ul><div class='clear'></div></div><div class='clear'></div> <div id='_SR_divPage' class='DisplayNone'></div><div class='margin5'><input type='button' value='"+_SR_C0047+"' class='button' onclick='$sr_SendItalkiMail()'/>&nbsp;&nbsp;<input type='button' value='"+_SR_C0064+"' class='buttong' onclick='_sr_Empty()' /></div></div><div id='_sr_NoFriends' style='display:none'><h3>"+_SR_SR010+"</h3></div></div></div></div><div id='_sr_FriendsTemple' style='display:none'><ul class='tag_common_right'><li><input type='checkbox' id='$MemberNo$' onclick='$sr_CheckFriend(\"$MemberNo$\",this)' /> <a href='/$MemberNo$.htm' target='_blank'>$NickName$</a></li></ul></div>";
        var obj = {}
        $ShowMessageBox$(_title,srBody,obj,_sr_Empty);
    }
}

//显示发送内容1：邮件、2：昵称
function $sr_SendContents()
{
    $get("_sr_SendContent").value="";$get("_sr_SendContent").style.display="none";$get("_sr_Send").style.display="";
}
//显示（0:Send an Email，1:italki friends）
function $sr_ShowType(val)
{  
    if(val==0){        
        $get("_sr_askQuestype1").style.display="";$get("_sr_askQuestype2").style.display="none";$get("_sr_spanQuesType1").className="first selATags";$get("_sr_spanQuesType2").className="unselATags";
    }
    else if(val==1){
        if(_SR_FriendPage.RecordCount==0)
        {
            $get("_sr_NoFriends").style.display="";
            $get("_sr_SelectFriends").style.display="none";
        }else{
            RendPageNavigator(_SR_FriendPage,"_SR_divPage","$sr_GetPageFriend");
        }
        $get("_sr_askQuestype1").style.display="none";$get("_sr_askQuestype2").style.display="";$get("_sr_spanQuesType1").className="first unselATags";$get("_sr_spanQuesType2").className="selATags";
    }
}
//全选与取消全选
function $SR_CheckAllBox(box)    
{ 
    _SR_CheckAOrF = false;
    _SR_CFNList.length=0;
    var fmlist = _SR_FriendNoList.length;
    for(var i = 0; i < fmlist; i++)
    {
        $get(_SR_FriendNoList[i]).checked = box.checked;        
    }
}
//朋友校验（朋友号）
function $sr_CheckFriend(friendNo,box)
{
    var friendInfo = {no:friendNo,na:box.value}
    if(box.checked)
    {   
        if(_SR_CheckAOrF)
        {
            for(var i=0;i<_SR_CFNList.length;i++)
            {
                if(_SR_CFNList[i].no==friendNo)
                {
                    _SR_CFNList.splice(i,1);
                }
            }
        }else{_SR_CFNList.push(friendInfo);}
    }
    else
    {
        if($get("_sr_checkDel").checked||_SR_CheckAOrF)
        {
            $get("_sr_checkDel").checked=false; 
            _SR_CheckAOrF=true;
            _SR_CFNList.push(friendInfo);
        }
        else
        {
            for(var i=0;i<_SR_CFNList.length;i++)
            {
                if(_SR_CFNList[i].no==friendNo)
                {
                    _SR_CFNList.splice(i,1);
                }
            }
        }   
    }     
}
function _sr_Empty()
{
    $EndMessageBox$();
}
//发送邮件
function $SR_SendEmail()
{ 
    var emails =  $get("_sr_txtEmail").value;
    if(emails=="")
    {
        $get("_sr_emOthErr").style.display="";
        return;
    }
    emails = emails.replace(/，/gi,",").toString();
    var mails = emails.replace(/,/gi,"<br/>").toString();
    $get("_sr_emOthErr").style.display="none";    
    $get("_sr_SendText").innerHTML=mails;
    $get("_sr_Send").style.display="none";
    $get("_sr_SendContent").style.display="";    
    WebServices.User.Public.SendMail(_SR_MyNickN,emails,__ShareURL);   
}
//发送italki 邮件
function $sr_SendItalkiMail()
{
    if((_SR_CFNList.length<=0&&!$get("_sr_checkDel").checked&&!_SR_CheckAOrF)||(_SR_FriendPage.RecordCount==_SR_CFNList.length&&_SR_CheckAOrF))
    {
        $get("_sr_error1ID").style.display="";        
        return;
    }    
	$get("_sr_error1ID").style.display="none";	
	if(!_SR_CheckAOrF)
	{
	    var nickNames="";
	    for(var i=0; i<_SR_CFNList.length; i++)
	    {
            nickNames+=_SR_CFNList[i].na+"<br/>";
	    }
	    $get("_sr_SendText").innerHTML = nickNames;
	    $get("_sr_Send").style.display="none";
	    $get("_sr_SendContent").style.display="";
	}
	var fMNArr = "";
	for(var i=0; i<_SR_CFNList.length; i++)
    {
        fMNArr+=_SR_CFNList[i].no;
    }
    _SR_CheckAOrF=$get("_sr_checkDel").checked?true:_SR_CheckAOrF;
    WebServices.User.Public.SendItalkiMail(_SR_MyNickN,fMNArr,__ShareURL,_SR_CheckAOrF);
    _SR_CFNList.length=0;
    _SR_CheckAOrF=false;
}

//获取页面数据（页索引）
function $sr_GetPageFriend(pageIndex)
{
	_SR_FriendNoList.length = 0;
    _SR_PageIndex = pageIndex;
    showProgressBar(true);	
    $sr_InitDataFriend(_SR_PageIndex);
}
//初始数据
function $sr_onsuccFriend(result)
{
    $sr_RendFriendList(result[0],"_sr_FriendsList");
    RendPageNavigator(result[1],"_SR_divPage","$sr_GetPageFriend");   
    showProgressBar(false);
}
//获取数据（页索引）
function $sr_InitDataFriend(pageIndex)
{   
    WebServices.User.Public.GetMemberFriends(_SR_MyMemberNo,pageIndex,_SR_PageSize,$sr_onsuccFriend);
}
//替换数据
function $sr_RendFriendList(list,divID)
{
    var domDiv =$get(divID);
    if(domDiv!=null)
    {    
        if(Sys.UI.DomElement.containsCssClass(domDiv, "DisplayNone"))Sys.UI.DomElement.removeCssClass(domDiv, "DisplayNone");         
        if($get("_sr_FriendsTemple")==null) return;        
        var item= $get("_sr_FriendsTemple").innerHTML;
        var listBuilder = new Sys.StringBuilder();
        var listCount = list.length;
        for (var index = 0; index < listCount; index++) 
        {
            var obj = list[index];                     
            var tmp = item.replace(/\$MemberNo\$/gi,obj.MemberNo).replace(/\$NickName\$/gi,obj.Nickname);            
            listBuilder.append(tmp); 
            _SR_FriendNoList[index] = obj.MemberNo;           
        }
        var sTemp = listBuilder.toString();domDiv.innerHTML = sTemp;
        for(var i = 0; i < listCount; i++)
        {
            var obj = list[i];
            if($get("_sr_checkDel").checked){$get(obj.MemberNo).checked = $get("_sr_checkDel").checked;}
            else
            {
                if(_SR_CFNList.length!=0)$get(obj.MemberNo).checked=true;
                for(var j = 0; j < _SR_CFNList.length; j++)
                {
                    if(_SR_CFNList[j].no!=obj.MemberNo&&!_SR_CheckAOrF){$get(obj.MemberNo).checked=false;}
                    else if(_SR_CFNList[j].no==obj.MemberNo&&_SR_CheckAOrF){$get(obj.MemberNo).checked=false;}                    
                }
            }                        
        }                   
    }
}